from typing import List


class NumArray:

    treeArray = []
    n = 0
    nums = []

    def __init__(self, nums: List[int]):
        self.n = len(nums)
        self.treeArray = [0] * (self.n + 1)
        self.nums = nums
        for i in range(0, self.n):
            j = i + 1
            while j <= self.n:
                self.treeArray[j] += self.nums[i]
                j += j & (-j)

    def update(self, index: int, val: int) -> None:
        dec = val - self.nums[index]
        index += 1
        self.nums[index] += dec
        while index <= self.n:
            self.treeArray[index] += dec
            index += index & (-index)
    def getValue(self, index) -> int:
        sum = 0
        while index > 0:
            sum += self.treeArray[index]
            index -= index & (-index)
        return sum

    def sumRange(self, left: int, right: int) -> int:
        return self.getValue(right + 1) - self.getValue(left)
if __name__ == '__main__':
    numArray = NumArray([-1])
    numArray.sumRange(0, 0)
    numArray.update(0, 1)
    numArray.sumRange(0, 0)
